import urllib.request

print("开始下载。")  # 3.3的写法

x = 8

# x的范围是0到103，循环

url = "https://api.bzqll.com/music/netease/url?key=579621905&id=526307800&br=999000"  # 在字符串中增加变量需要用str()

    # url = "http://www.wzsky.net/img2013/uploadimg/20130906/1216294.jpg"#121629103.jpg是最后一个文件

    # 伪装浏览器，这里没用到
    # headers = ('User-Agent','Mozilla/5.0 (Linux; Android 4.4.4; en-us; Nexus 5 Build/JOP40D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2307.2 Mobile Safari/537.36')

headers = ('Referer', 'https://api.bzqll.com/music/netease/url?key=579621905&id=526307800&br=999000')  # 防盗链，修改访问来源

opener = urllib.request.build_opener()
opener.addheaders = [headers]

data = opener.open(url).read()

with open("d:/" + 'ni' + ".mp3", "wb") as code:
    code.write(data)

print(url)  # 如果不放到这里就会只下载最后一个文件
print("下载完成。")
